<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html lang="en">

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <title>LCOV - id:000977,sync:fuzzer2,src:001052.lcov_info_final - test/integration/encoding_test.cpp</title>
  <link rel="stylesheet" type="text/css" href="../../gcov.css">
</head>

<body>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="title">LCOV - code coverage report</td></tr>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>

    <tr>
      <td width="100%">
        <table cellpadding=1 border=0 width="100%">
          <tr>
            <td width="10%" class="headerItem">Current view:</td>
            <td width="35%" class="headerValue"><a href="../../index.html">top level</a> - <a href="index.html">test/integration</a> - encoding_test.cpp<span style="font-size: 80%;"> (source / <a href="encoding_test.cpp.func-sort-c.html">functions</a>)</span></td>
            <td width="5%"></td>
            <td width="15%"></td>
            <td width="10%" class="headerCovTableHead">Hit</td>
            <td width="10%" class="headerCovTableHead">Total</td>
            <td width="15%" class="headerCovTableHead">Coverage</td>
          </tr>
          <tr>
            <td class="headerItem">Test:</td>
            <td class="headerValue">id:000977,sync:fuzzer2,src:001052.lcov_info_final</td>
            <td></td>
            <td class="headerItem">Lines:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">124</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr>
            <td class="headerItem">Date:</td>
            <td class="headerValue">2016-03-13 10:42:47</td>
            <td></td>
            <td class="headerItem">Functions:</td>
            <td class="headerCovTableEntry">0</td>
            <td class="headerCovTableEntry">54</td>
            <td class="headerCovTableEntryLo">0.0 %</td>
          </tr>
          <tr><td><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
        </table>
      </td>
    </tr>

    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
  </table>

  <table cellpadding=0 cellspacing=0 border=0>
    <tr>
      <td><br></td>
    </tr>
    <tr>
      <td>
<pre class="sourceHeading">          Line data    Source code</pre>
<pre class="source">
<a name="1"><span class="lineNum">       1 </span>            : #include &lt;sstream&gt;</a>
<span class="lineNum">       2 </span>            : 
<span class="lineNum">       3 </span>            : #include &quot;handler_test.h&quot;
<span class="lineNum">       4 </span>            : #include &quot;yaml-cpp/yaml.h&quot;  // IWYU pragma: keep
<span class="lineNum">       5 </span>            : 
<span class="lineNum">       6 </span>            : #include &quot;gtest/gtest.h&quot;
<span class="lineNum">       7 </span>            : 
<span class="lineNum">       8 </span>            : using ::testing::_;
<span class="lineNum">       9 </span>            : using ::testing::InSequence;
<span class="lineNum">      10 </span>            : 
<span class="lineNum">      11 </span>            : namespace YAML {
<span class="lineNum">      12 </span>            : namespace {
<a name="13"><span class="lineNum">      13 </span>            : typedef void (*EncodingFn)(std::ostream&amp;, int);</a>
<span class="lineNum">      14 </span>            : 
<span class="lineNum">      15 </span><span class="lineNoCov">          0 : inline char Byte(int ch) {</span>
<span class="lineNum">      16 </span>            :   return static_cast&lt;char&gt;(
<span class="lineNum">      17 </span><span class="lineNoCov">          0 :       static_cast&lt;unsigned char&gt;(static_cast&lt;unsigned int&gt;(ch)));</span>
<a name="18"><span class="lineNum">      18 </span>            : }</a>
<span class="lineNum">      19 </span>            : 
<span class="lineNum">      20 </span><span class="lineNoCov">          0 : void EncodeToUtf8(std::ostream&amp; stream, int ch) {</span>
<span class="lineNum">      21 </span><span class="lineNoCov">          0 :   if (ch &lt;= 0x7F) {</span>
<span class="lineNum">      22 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(ch);</span>
<span class="lineNum">      23 </span><span class="lineNoCov">          0 :   } else if (ch &lt;= 0x7FF) {</span>
<span class="lineNum">      24 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0xC0 | (ch &gt;&gt; 6));</span>
<span class="lineNum">      25 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0x80 | (ch &amp; 0x3F));</span>
<span class="lineNum">      26 </span><span class="lineNoCov">          0 :   } else if (ch &lt;= 0xFFFF) {</span>
<span class="lineNum">      27 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0xE0 | (ch &gt;&gt; 12));</span>
<span class="lineNum">      28 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0x80 | ((ch &gt;&gt; 6) &amp; 0x3F));</span>
<span class="lineNum">      29 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0x80 | (ch &amp; 0x3F));</span>
<span class="lineNum">      30 </span><span class="lineNoCov">          0 :   } else if (ch &lt;= 0x1FFFFF) {</span>
<span class="lineNum">      31 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0xF0 | (ch &gt;&gt; 18));</span>
<span class="lineNum">      32 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0x80 | ((ch &gt;&gt; 12) &amp; 0x3F));</span>
<span class="lineNum">      33 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0x80 | ((ch &gt;&gt; 6) &amp; 0x3F));</span>
<span class="lineNum">      34 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(0x80 | (ch &amp; 0x3F));</span>
<span class="lineNum">      35 </span>            :   }
<a name="36"><span class="lineNum">      36 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">      37 </span>            : 
<span class="lineNum">      38 </span><span class="lineNoCov">          0 : bool SplitUtf16HighChar(std::ostream&amp; stream, EncodingFn encoding, int ch) {</span>
<span class="lineNum">      39 </span><span class="lineNoCov">          0 :   int biasedValue = ch - 0x10000;</span>
<span class="lineNum">      40 </span><span class="lineNoCov">          0 :   if (biasedValue &lt; 0) {</span>
<span class="lineNum">      41 </span><span class="lineNoCov">          0 :     return false;</span>
<span class="lineNum">      42 </span>            :   }
<span class="lineNum">      43 </span><span class="lineNoCov">          0 :   int high = 0xD800 | (biasedValue &gt;&gt; 10);</span>
<span class="lineNum">      44 </span><span class="lineNoCov">          0 :   int low = 0xDC00 | (biasedValue &amp; 0x3FF);</span>
<span class="lineNum">      45 </span><span class="lineNoCov">          0 :   encoding(stream, high);</span>
<span class="lineNum">      46 </span><span class="lineNoCov">          0 :   encoding(stream, low);</span>
<span class="lineNum">      47 </span><span class="lineNoCov">          0 :   return true;</span>
<a name="48"><span class="lineNum">      48 </span>            : }</a>
<span class="lineNum">      49 </span>            : 
<span class="lineNum">      50 </span><span class="lineNoCov">          0 : void EncodeToUtf16LE(std::ostream&amp; stream, int ch) {</span>
<span class="lineNum">      51 </span><span class="lineNoCov">          0 :   if (!SplitUtf16HighChar(stream, &amp;EncodeToUtf16LE, ch)) {</span>
<span class="lineNum">      52 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(ch &amp; 0xFF) &lt;&lt; Byte(ch &gt;&gt; 8);</span>
<span class="lineNum">      53 </span>            :   }
<a name="54"><span class="lineNum">      54 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">      55 </span>            : 
<span class="lineNum">      56 </span><span class="lineNoCov">          0 : void EncodeToUtf16BE(std::ostream&amp; stream, int ch) {</span>
<span class="lineNum">      57 </span><span class="lineNoCov">          0 :   if (!SplitUtf16HighChar(stream, &amp;EncodeToUtf16BE, ch)) {</span>
<span class="lineNum">      58 </span><span class="lineNoCov">          0 :     stream &lt;&lt; Byte(ch &gt;&gt; 8) &lt;&lt; Byte(ch &amp; 0xFF);</span>
<span class="lineNum">      59 </span>            :   }
<a name="60"><span class="lineNum">      60 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">      61 </span>            : 
<span class="lineNum">      62 </span><span class="lineNoCov">          0 : void EncodeToUtf32LE(std::ostream&amp; stream, int ch) {</span>
<span class="lineNum">      63 </span><span class="lineNoCov">          0 :   stream &lt;&lt; Byte(ch &amp; 0xFF) &lt;&lt; Byte((ch &gt;&gt; 8) &amp; 0xFF) &lt;&lt; Byte((ch &gt;&gt; 16) &amp; 0xFF)</span>
<span class="lineNum">      64 </span><span class="lineNoCov">          0 :          &lt;&lt; Byte((ch &gt;&gt; 24) &amp; 0xFF);</span>
<a name="65"><span class="lineNum">      65 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">      66 </span>            : 
<span class="lineNum">      67 </span><span class="lineNoCov">          0 : void EncodeToUtf32BE(std::ostream&amp; stream, int ch) {</span>
<span class="lineNum">      68 </span><span class="lineNoCov">          0 :   stream &lt;&lt; Byte((ch &gt;&gt; 24) &amp; 0xFF) &lt;&lt; Byte((ch &gt;&gt; 16) &amp; 0xFF)</span>
<span class="lineNum">      69 </span><span class="lineNoCov">          0 :          &lt;&lt; Byte((ch &gt;&gt; 8) &amp; 0xFF) &lt;&lt; Byte(ch &amp; 0xFF);</span>
<a name="70"><span class="lineNum">      70 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">      71 </span>            : 
<a name="72"><span class="lineNum">      72 </span><span class="lineNoCov">          0 : class EncodingTest : public HandlerTest {</span></a>
<span class="lineNum">      73 </span>            :  protected:
<span class="lineNum">      74 </span><span class="lineNoCov">          0 :   void SetUpEncoding(EncodingFn encoding, bool declareEncoding) {</span>
<span class="lineNum">      75 </span><span class="lineNoCov">          0 :     if (declareEncoding) {</span>
<span class="lineNum">      76 </span><span class="lineNoCov">          0 :       encoding(m_yaml, 0xFEFF);</span>
<span class="lineNum">      77 </span>            :     }
<span class="lineNum">      78 </span>            : 
<span class="lineNum">      79 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x0021, 0x007E);  // Basic Latin</span>
<span class="lineNum">      80 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x00A1, 0x00FF);  // Latin-1 Supplement</span>
<span class="lineNum">      81 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x0660, 0x06FF);  // Arabic (largest contiguous block)</span>
<span class="lineNum">      82 </span>            : 
<span class="lineNum">      83 </span>            :     // CJK unified ideographs (multiple lines)
<span class="lineNum">      84 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x4E00, 0x4EFF);</span>
<span class="lineNum">      85 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x4F00, 0x4FFF);</span>
<span class="lineNum">      86 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x5000, 0x51FF);  // 512 character line</span>
<span class="lineNum">      87 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x5200, 0x54FF);  // 768 character line</span>
<span class="lineNum">      88 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x5500, 0x58FF);  // 1024 character line</span>
<span class="lineNum">      89 </span>            : 
<span class="lineNum">      90 </span><span class="lineNoCov">          0 :     AddEntry(encoding, 0x103A0, 0x103C3);  // Old Persian</span>
<span class="lineNum">      91 </span>            : 
<span class="lineNum">      92 </span><span class="lineNoCov">          0 :     m_yaml.seekg(0, std::ios::beg);</span>
<a name="93"><span class="lineNum">      93 </span><span class="lineNoCov">          0 :   }</span></a>
<span class="lineNum">      94 </span>            : 
<span class="lineNum">      95 </span><span class="lineNoCov">          0 :   void Run() {</span>
<span class="lineNum">      96 </span><span class="lineNoCov">          0 :     InSequence sequence;</span>
<span class="lineNum">      97 </span><span class="lineNoCov">          0 :     EXPECT_CALL(handler, OnDocumentStart(_));</span>
<span class="lineNum">      98 </span><span class="lineNoCov">          0 :     EXPECT_CALL(handler, OnSequenceStart(_, &quot;?&quot;, 0, EmitterStyle::Block));</span>
<span class="lineNum">      99 </span><span class="lineNoCov">          0 :     for (std::size_t i = 0; i &lt; m_entries.size(); i++) {</span>
<span class="lineNum">     100 </span><span class="lineNoCov">          0 :       EXPECT_CALL(handler, OnScalar(_, &quot;!&quot;, 0, m_entries[i]));</span>
<span class="lineNum">     101 </span>            :     }
<span class="lineNum">     102 </span><span class="lineNoCov">          0 :     EXPECT_CALL(handler, OnSequenceEnd());</span>
<span class="lineNum">     103 </span><span class="lineNoCov">          0 :     EXPECT_CALL(handler, OnDocumentEnd());</span>
<span class="lineNum">     104 </span>            : 
<span class="lineNum">     105 </span><span class="lineNoCov">          0 :     Parse(m_yaml.str());</span>
<span class="lineNum">     106 </span><span class="lineNoCov">          0 :   }</span>
<span class="lineNum">     107 </span>            : 
<span class="lineNum">     108 </span>            :  private:
<span class="lineNum">     109 </span>            :   std::stringstream m_yaml;
<a name="110"><span class="lineNum">     110 </span>            :   std::vector&lt;std::string&gt; m_entries;</a>
<span class="lineNum">     111 </span>            : 
<span class="lineNum">     112 </span><span class="lineNoCov">          0 :   void AddEntry(EncodingFn encoding, int startCh, int endCh) {</span>
<span class="lineNum">     113 </span><span class="lineNoCov">          0 :     encoding(m_yaml, '-');</span>
<span class="lineNum">     114 </span><span class="lineNoCov">          0 :     encoding(m_yaml, ' ');</span>
<span class="lineNum">     115 </span><span class="lineNoCov">          0 :     encoding(m_yaml, '|');</span>
<span class="lineNum">     116 </span><span class="lineNoCov">          0 :     encoding(m_yaml, '\n');</span>
<span class="lineNum">     117 </span><span class="lineNoCov">          0 :     encoding(m_yaml, ' ');</span>
<span class="lineNum">     118 </span><span class="lineNoCov">          0 :     encoding(m_yaml, ' ');</span>
<span class="lineNum">     119 </span>            : 
<span class="lineNum">     120 </span><span class="lineNoCov">          0 :     std::stringstream entry;</span>
<span class="lineNum">     121 </span><span class="lineNoCov">          0 :     for (int ch = startCh; ch &lt;= endCh; ++ch) {</span>
<span class="lineNum">     122 </span><span class="lineNoCov">          0 :       encoding(m_yaml, ch);</span>
<span class="lineNum">     123 </span><span class="lineNoCov">          0 :       EncodeToUtf8(entry, ch);</span>
<span class="lineNum">     124 </span>            :     }
<span class="lineNum">     125 </span><span class="lineNoCov">          0 :     encoding(m_yaml, '\n');</span>
<span class="lineNum">     126 </span><span class="lineNoCov">          0 :     EncodeToUtf8(entry, '\n');</span>
<span class="lineNum">     127 </span>            : 
<span class="lineNum">     128 </span><span class="lineNoCov">          0 :     m_entries.push_back(entry.str());</span>
<span class="lineNum">     129 </span><span class="lineNoCov">          0 :   }</span>
<a name="130"><span class="lineNum">     130 </span>            : };</a>
<span class="lineNum">     131 </span>            : 
<span class="lineNum">     132 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF8_noBOM) {</span>
<span class="lineNum">     133 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf8, false);</span>
<span class="lineNum">     134 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="135"><span class="lineNum">     135 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     136 </span>            : 
<span class="lineNum">     137 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF8_BOM) {</span>
<span class="lineNum">     138 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf8, true);</span>
<span class="lineNum">     139 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="140"><span class="lineNum">     140 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     141 </span>            : 
<span class="lineNum">     142 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF16LE_noBOM) {</span>
<span class="lineNum">     143 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf16LE, false);</span>
<span class="lineNum">     144 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="145"><span class="lineNum">     145 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     146 </span>            : 
<span class="lineNum">     147 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF16LE_BOM) {</span>
<span class="lineNum">     148 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf16LE, true);</span>
<span class="lineNum">     149 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="150"><span class="lineNum">     150 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     151 </span>            : 
<span class="lineNum">     152 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF16BE_noBOM) {</span>
<span class="lineNum">     153 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf16BE, false);</span>
<span class="lineNum">     154 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="155"><span class="lineNum">     155 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     156 </span>            : 
<span class="lineNum">     157 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF16BE_BOM) {</span>
<span class="lineNum">     158 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf16BE, true);</span>
<span class="lineNum">     159 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="160"><span class="lineNum">     160 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     161 </span>            : 
<span class="lineNum">     162 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF32LE_noBOM) {</span>
<span class="lineNum">     163 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf32LE, false);</span>
<span class="lineNum">     164 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="165"><span class="lineNum">     165 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     166 </span>            : 
<span class="lineNum">     167 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF32LE_BOM) {</span>
<span class="lineNum">     168 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf32LE, true);</span>
<span class="lineNum">     169 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="170"><span class="lineNum">     170 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     171 </span>            : 
<span class="lineNum">     172 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF32BE_noBOM) {</span>
<span class="lineNum">     173 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf32BE, false);</span>
<span class="lineNum">     174 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="175"><span class="lineNum">     175 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     176 </span>            : 
<span class="lineNum">     177 </span><span class="lineNoCov">          0 : TEST_F(EncodingTest, UTF32BE_BOM) {</span>
<span class="lineNum">     178 </span><span class="lineNoCov">          0 :   SetUpEncoding(&amp;EncodeToUtf32BE, true);</span>
<span class="lineNum">     179 </span><span class="lineNoCov">          0 :   Run();</span>
<a name="180"><span class="lineNum">     180 </span><span class="lineNoCov">          0 : }</span></a>
<span class="lineNum">     181 </span>            : }
<span class="lineNum">     182 </span><span class="lineNoCov">          0 : }</span>
</pre>
      </td>
    </tr>
  </table>
  <br>

  <table width="100%" border=0 cellspacing=0 cellpadding=0>
    <tr><td class="ruler"><img src="../../glass.png" width=3 height=3 alt=""></td></tr>
    <tr><td class="versionInfo">Generated by: <a href="http://ltp.sourceforge.net/coverage/lcov.php" target="_parent">LCOV version 1.11</a></td></tr>
  </table>
  <br>

</body>
</html>
